package com.ycMc.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
    public static final String REG_PHONE = "^[1][3,4,5,6,7,8,9][0-9]{9}$";
    public static final String REG_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    //6-16位，字母开头包括数字
    public static final String REG_CLOTHERID = "^\\w{4,16}$";
    //8-16位，中英文混合
    public static  final String REG_PASSWORD="((?=.*\\d)(?=.*\\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$";

    public static boolean isMobile(String str) {
        return doMatch(str, REG_PHONE);
    }

    public static boolean doMatch(String str, String regex) {
        if (str == null) {
            return false;
        }
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile(regex);
        m = p.matcher(str);
        b = m.matches();
        return b;
    }

    public static boolean isEmail(String str) {
        return doMatch(str, REG_EMAIL);
    }

    public static boolean isRight(String clotherId) {
        return doMatch(clotherId, REG_CLOTHERID);
    }

    public static boolean isPassword(String password)  {return  doMatch(password,REG_PASSWORD);    }

}
